Page({
  data: {
    isLoggedIn: false,
    userInfo: {}
  },
  
  onShow() {
    const userInfo = wx.getStorageSync('userInfo');
    this.setData({ 
      userInfo,
      isLoggedIn: !!userInfo 
    });
  },
  navigateToLogin(){
    wx.navigateTo({
      url: '/pages/mine/login/login',
    })
  },
  // 跳转个人资料页
  navigateToProfile() {
    wx.navigateTo({
      url: '/pages/mine/edit/ediy',
    })
    
  },

  // 版本检测
  checkVersion() {
    wx.showToast({ title: '已是最新版本', icon: 'success' });
  },

  // 退出登录
  showLogoutConfirm() {
    wx.showModal({
      title: '确认退出',
      content: '退出后将无法使用个人功能',
      success: (res) => {
        if (res.confirm) {
          wx.removeStorageSync('userInfo');
          wx.removeStorageSync('token');
          this.setData({ isLoggedIn: false, userInfo: {} });
          wx.showToast({ title: '已退出' });
        }
      }
    });
  }
});